<template>
    <my-dialog v-if="dialogVisible" :show.sync="dialogVisible" :showBtn="false" width="500px" title="发布出售" @close="$emit('close')">
        <div>
            <el-form size="small" ref="ruleForm" label-width="100px" class="demo-ruleForm">
                <el-form-item label="出售模式" prop="name">
                    <el-radio-group v-model="sellMOdel" @change="settlementCurrency=[]">
                        <el-radio :label="1" border>拍卖</el-radio>
                        <el-radio :label="2" border>寄售</el-radio>
                    </el-radio-group>
                </el-form-item>  
                <template v-if="sellMOdel==1">
                    <el-form-item label="设置初始价格" prop="amount">
                        <el-input v-model="auctionFrom.amount" placeholder="请输入NFT拍卖的初始价格"></el-input>
                    </el-form-item>  
                    <el-form-item label="拍卖开始时间" prop="startTime">
                        <el-date-picker
                        v-model="auctionFrom.startTime"
                        type="datetime"
                        format='yyyy-MM-dd HH:mm'
                        value-format="yyyy-MM-dd HH:mm:ss"
                        style="width:100%"
                        placeholder="选择日期时间">
                        </el-date-picker>
                    </el-form-item> 
                    <el-form-item label="拍卖结束时间" prop="endTime">
                        <el-date-picker
                        v-model="auctionFrom.endTime"
                        type="datetime"
                        style="width:100%"
                        format='yyyy-MM-dd HH:mm'
                        value-format="yyyy-MM-dd HH:mm:ss"
                        placeholder="选择日期时间">
                        </el-date-picker>
                    </el-form-item> 
                </template>
                <template v-if="sellMOdel==2">
                    <el-form-item label="设置寄售价格">
                        <el-input v-model="amount" placeholder="请输入NFT寄售价格"></el-input>
                    </el-form-item> 
                </template>
                <el-form-item label="结算货币">
                    <template  v-if="sellMOdel==1">
                        <el-checkbox-group v-model="settlementCurrency">
                            <el-checkbox label="CXT"></el-checkbox>
                            <el-checkbox label="ETH"></el-checkbox>
                            <el-checkbox label="USDT"></el-checkbox>
                        </el-checkbox-group>
                    </template>
                    <template  v-else>
                        <el-checkbox-group v-model="settlementCurrency">
                            <el-checkbox label="CXT"></el-checkbox>
                            <el-checkbox label="ETH"></el-checkbox>
                            <el-checkbox label="USDT"></el-checkbox>
                        </el-checkbox-group>
                        <!-- <el-radio-group v-model="settlementCurrency">
                            <el-radio label="CXT"></el-radio>
                            <el-radio label="ETH"></el-radio>
                            <el-radio label="USDT"></el-radio>
                        </el-radio-group> -->
                    </template>
                </el-form-item> 
                <el-form-item label="发布平台">
                    <el-checkbox-group v-model="publishingPlatform">
                        <el-checkbox label="collext"></el-checkbox>
                        <el-checkbox label="Opensea"></el-checkbox>
                    </el-checkbox-group>
                </el-form-item> 
            </el-form> 
        </div>
        <div style="text-align: right;padding: 10px 0 20px 0;">
            <el-button  size="small" @click="$emit('close')" icon="el-icon-close">取 消</el-button>
            <el-button type="primary" size="small" icon="el-icon-check" @click="submitData">确 定</el-button>
        </div>
    </my-dialog> 
</template>
<script>
import {
    apply_sell,
  apply_auction,
} from '@/api/collext'
import myDialog from '@/components/public/myDialog.vue'
export default {
    components:{
        myDialog
    },
    props:{
        id:''
    },
    data(){
        return{
            dialogVisible:true,
            sellMOdel:1,
            auctionFrom:{
                amount:'',
                startTime:'',
                endTime:''
            },
            settlementCurrency:[],
            publishingPlatform:[],
            amount:''
        }
    },
    methods:{
        submitData(){
            if(this.sellMOdel == 1){
                this.applyAuction()
            }else if(this.sellMOdel == 2){
                this.applySell()
            }
        },
        applyAuction(){
            if(!this.auctionFrom.amount){
                return this.$message.warning('请输入NFT拍卖初始价格')
            }else if(!this.auctionFrom.startTime){
                return this.$message.warning('请选择拍卖开始时间')
            }else if(!this.auctionFrom.endTime){
                return this.$message.warning('请选择拍卖结束时间')
            }else if(this.settlementCurrency.length<1){
                return this.$message.warning('请选择结算货币')
            }else if(this.publishingPlatform.length<1){
                return this.$message.warning('请选择发布平台')
            }
            apply_auction({
               ...this.auctionFrom,
               bornId:this.id,
               settlementCurrency:this.settlementCurrency.join(','),
               publishingPlatform:this.publishingPlatform.join(','),
            }).then(res=>{
                if(res.success){
                    this.$message.success('发布成功!')
                    this.$emit('close')
                }else{
                   // this.$message.error(res.message)
                }
            })
        },
        applySell(){
            if(!this.amount){
                return this.$message.warning('请输入NFT寄卖价格')
            }else if(!this.settlementCurrency || this.settlementCurrency.length<1){
                return this.$message.warning('请选择结算货币')
            }else if(this.publishingPlatform.length<1){
                return this.$message.warning('请选择发布平台')
            }
            apply_sell({
                amount:this.amount,
               bornId:this.id,
               settlementCurrency:this.settlementCurrency.join(','),
               publishingPlatform:this.publishingPlatform.join(','),
            }).then(res=>{
                if(res.success){
                    this.$message.success('发布成功!')
                    this.$emit('close')
                }else{
                   // this.$message.error(res.message)
                }
            })
        }
    }
}
</script>